home *** CD-ROM | disk | FTP | other *** search
/ Aminet 33 / Aminet 33 - October 1999.iso / Aminet / dev / c / GAPLib.lha / GAPLib / wrappers / c_plus_plus / wrapper.cc < prev   
Encoding:
C/C++ Source or Header  |  1999-05-05  |  2.9 KB  |  207 lines

  1.  
  2. #include <GAP.hh>
  3.  
  4. /* Population implementation */
  5.  
  6. GPopulation::GPopulation(int Num,int Size,struct TagItem *TagList)
  7. {
  8. this->Pop = CreatePopulation(Num,Size,TagList);
  9. }
  10.  
  11. GPopulation::GPopulation(int Num,int Size)
  12. {
  13. this->Pop = CreatePopulation(Num,Size,0);
  14. }
  15.  
  16. GPopulation::~GPopulation()
  17. {
  18. DeletePopulation(this->Pop);
  19. }
  20.  
  21. struct Popstat *GPopulation::GetStats(void)
  22. {
  23. return(&this->Pop->Stat);
  24. }
  25.  
  26. void *GPopulation::GetMember(int n)
  27. {
  28. return(PopMember(this->Pop,n));
  29. }
  30.  
  31. void GPopulation::Evolve(struct TagItem *TagList)
  32. {
  33. this->Pop = ::Evolve(this->Pop,TagList);
  34. }
  35.  
  36. void GPopulation::Evolve(TagSet *Set)
  37. {
  38. this->Pop = ::Evolve(this->Pop,Set->List());
  39. }
  40.  
  41. int GPopulation::GetSize(void)
  42. {
  43. return(this->Pop->NumPolys);
  44. }
  45.  
  46. void GPopulation::SetSize(int newsize)
  47. {
  48. if(newsize>0) {
  49.     this->Pop->NumPolys = newsize;
  50. }
  51. }
  52.  
  53. int GPopulation::GetGeneration(void)
  54. {
  55. return(this->Pop->Generation);
  56. }
  57.  
  58. /* TagSet implementation */
  59.  
  60. TagSet::TagSet()
  61. {
  62. TagList = new struct TagItem[8];
  63. TagList[0].ti_Tag = TAG_DONE;
  64. MIdx = 7;
  65. }
  66.  
  67. TagSet::TagSet(struct TagItem *Tags)
  68. {
  69. int i,n,t;
  70. struct TagItem *tag;
  71.  
  72. i=n=t=0;
  73. tag=Tags;
  74.  
  75. while(!n) {    /* Count no. of items in parameter taglist. */
  76.     t++;
  77.     switch(tag[i].ti_Tag) {
  78.     case    TAG_DONE:
  79.         n=1;
  80.     continue;
  81.     case    TAG_MORE:
  82.         tag = (struct TagItem *)tag[i].ti_Data;
  83.         i=0;
  84.         t--;
  85.     continue;
  86.     }
  87.     i++;
  88. }
  89.  
  90. TagList = new struct TagItem[t];
  91.  
  92. MIdx = t-1;
  93.  
  94. i=n=t=0;
  95. tag=Tags;
  96.  
  97. while(!n) {    /* Copy contents of parameter taglist. */
  98.     TagList[t].ti_Tag = tag[i].ti_Tag;
  99.     TagList[t].ti_Data = tag[i].ti_Data;
  100.     t++;
  101.     switch(tag[i].ti_Tag) {
  102.     case    TAG_DONE:
  103.         n=1;
  104.     continue;
  105.     case    TAG_MORE:
  106.         tag = (struct TagItem *)tag[i].ti_Data;
  107.         i=0;
  108.         t--;
  109.     continue;
  110.     }
  111.     i++;
  112. }
  113.  
  114. }
  115.  
  116. TagSet::~TagSet()
  117. {
  118. struct TagItem *tag;
  119.  
  120. while((tag=Find(TAG_MORE))!=0) {
  121.     tag = (struct TagItem *)tag->ti_Data;
  122.     delete TagList;
  123.     TagList = tag;
  124. }
  125.  
  126. delete TagList;
  127.  
  128. }
  129.  
  130. void TagSet::Del(Tag type)
  131. {
  132. struct TagItem *tag;
  133.  
  134. tag = Find(type);
  135.  
  136. if(tag!=0) {
  137.     tag->ti_Tag = TAG_IGNORE;
  138. }
  139.  
  140. }
  141.  
  142. void TagSet::Set(Tag type,IPTR data)
  143. {
  144. struct TagItem *tag;
  145.  
  146. tag = Find(type);
  147.  
  148. if(tag!=0) {
  149.     tag->ti_Data = data;
  150. } else {
  151.     tag = Find(TAG_DONE);
  152.     if(CIdx<MIdx) {
  153.         tag[1].ti_Tag = TAG_DONE;
  154.         tag->ti_Tag = type;
  155.         tag->ti_Data = data;
  156.     } else {
  157.         tag->ti_Data = (IPTR) new struct TagItem[MIdx+1];
  158.         tag->ti_Tag = TAG_MORE;
  159.         tag = (struct TagItem *)tag->ti_Data;
  160.         tag[1].ti_Tag = TAG_DONE;
  161.         tag->ti_Tag = type;
  162.         tag->ti_Data = data;
  163.     }
  164. }
  165.  
  166. }
  167.  
  168. IPTR TagSet::Get(Tag type)
  169. {
  170. struct TagItem *tag;
  171. tag = Find(type);
  172. if(tag!=0) {
  173.     return(tag->ti_Data);
  174. }
  175.  
  176. return(0);
  177. }
  178.  
  179. int TagSet::Exists(Tag type)
  180. {
  181. struct TagItem *tag;
  182. tag = Find(type);
  183. if(tag!=0) {
  184.     return(1);
  185. }
  186. return(0);
  187. }
  188.  
  189. struct TagItem *TagSet::Find(Tag type)
  190. {
  191. int i;
  192. struct TagItem *tag = TagList;
  193.  
  194. i = -1;
  195. while(tag[++i].ti_Tag!=TAG_DONE) {
  196.     if(tag[i].ti_Tag == type) {
  197.         CIdx = i;
  198.         return(&tag[i]);
  199.     } else if(tag[i].ti_Tag == TAG_MORE) {
  200.         tag = (struct TagItem *)tag[i].ti_Data;
  201.         i = -1;
  202.     }
  203. }
  204.  
  205. return(0);
  206. }
  207.